package com.jkt.rms.business.base;

import java.lang.Comparable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.io.Serializable;

import com.jkt.rms.commons.utils.RMSException;


/**
 * This is an object that contains data related to the Rate table.
 * Do not modify this class because it will be overwritten if the configuration file
 * related to this class is modified.
 *
 * @hibernate.class
 *  table="Rate"
 */

public abstract class BaseRate  implements Comparable, Serializable {

	public static String REF = "Rate";
	public static String PROP_STATUS = "status";
	public static String PROP_UPDATED_DATE = "updatedDate";
	public static String PROP_UPDATED_BY = "updatedBy";
	public static String PROP_STARTDATE = "startdate";
	public static String PROP_ROLE_CODE = "roleCode";
	public static String PROP_ID = "id";
	public static String PROP_LOCATION_CODE = "locationCode";
	public static String PROP_VENDOR_CODE = "vendorCode";
	public static String PROP_ENDDATE = "enddate";
	public static String PROP_RATE = "Rate";
	public static String PROP_CURRENCY_ID = "currencyId";


	// constructors
	public BaseRate () {
		initialize();
	}

	/**
	 * Constructor for primary key
	 */
	public BaseRate (int id) {
		this.setId(id);
		initialize();
	}

	/**
	 * Constructor for required fields
	 */
	public BaseRate (
		int id,
		java.lang.String roleCode,
		java.lang.String vendorCode,
		float rate,
		java.lang.String locationCode) {

		this.setId(id);
		this.setRoleCode(roleCode);
		this.setVendorCode(vendorCode);
		this.setRate(rate);
		this.setLocationCode(locationCode);
		initialize();
	}

	protected void initialize () {}



	private int hashCode = Integer.MIN_VALUE;

	// primary key
	private int id;

	// fields
	private java.lang.String roleCode;
	private java.lang.String vendorCode;
	private float rate;
	private java.lang.String locationCode;
	private java.lang.String updatedBy;
	private java.util.Date updatedDate;
	private java.util.Date startdate;
	private java.util.Date enddate;
	private char status;
	private int currencyId;

	public int getCurrencyId() {
		return currencyId;
	}

	public void setCurrencyId(int currencyId) {
		this.currencyId = currencyId;
	}



	// collections
	private java.util.Set<com.jkt.rms.business.Resource> resourceRates;



	/**
	 * Return the unique identifier of this class
     * @hibernate.id
     *  generator-class="native"
     *  column="rate_id"
     */
	public int getId () {
		return id;
	}

	/**
	 * Set the unique identifier of this class
	 * @param id the new ID
	 */
	public void setId (int id) {
		this.id = id;
		this.hashCode = Integer.MIN_VALUE;
	}




	/**
	 * Return the value associated with the column: role_code
	 */
	public java.lang.String getRoleCode () {
		return roleCode;
	}

	/**
	 * Set the value related to the column: role_code
	 * @param roleCode the role_code value
	 */
	public void setRoleCode (java.lang.String roleCode) {
		this.roleCode = roleCode;
	}



	/**
	 * Return the value associated with the column: Vendor_code
	 */
	public java.lang.String getVendorCode () {
		return vendorCode;
	}

	/**
	 * Set the value related to the column: Vendor_code
	 * @param vendorCode the Vendor_code value
	 */
	public void setVendorCode (java.lang.String vendorCode) {
		this.vendorCode = vendorCode;
	}



	/**
	 * Return the value associated with the column: rate
	 */
	public float getRate () {
		return rate;
	}

	/**
	 * Set the value related to the column: rate
	 * @param rate the rate value
	 */
	public void setRate (float rate) {
		this.rate = rate;
	}



	/**
	 * Return the value associated with the column: location_code
	 */
	public java.lang.String getLocationCode () {
		return locationCode;
	}

	/**
	 * Set the value related to the column: location_code
	 * @param locationCode the location_code value
	 */
	public void setLocationCode (java.lang.String locationCode) {
		this.locationCode = locationCode;
	}



	/**
	 * Return the value associated with the column: updated_by
	 */
	public java.lang.String getUpdatedBy () {
		return updatedBy;
	}

	/**
	 * Set the value related to the column: updated_by
	 * @param updatedBy the updated_by value
	 */
	public void setUpdatedBy (java.lang.String updatedBy) {
		this.updatedBy = updatedBy;
	}



	/**
	 * Return the value associated with the column: updated_date
	 */
	public java.util.Date getUpdatedDate () {
		return updatedDate;
	}

	/**
	 * Set the value related to the column: updated_date
	 * @param updatedDate the updated_date value
	 */
	public void setUpdatedDate (java.util.Date updatedDate) {
		this.updatedDate = updatedDate;
	}



	/**
	 * Return the value associated with the column: start_date
	 */
	public java.util.Date getStartdate () {
		return startdate;
	}

	/**
	 * Set the value related to the column: start_date
	 * @param startdate the start_date value
	 */
	public void setStartdate (java.util.Date startdate) {
		this.startdate = startdate;
	}

	public void setStartdate (String startdate) throws RMSException{
		SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
		try {
			this.startdate = format.parse(startdate);
		} catch (ParseException e) {
			throw new RMSException(e);
		}
	}
	
	public void setEnddate (String enddate) throws RMSException{
		SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
		try {
			this.enddate = format.parse(enddate);
		} catch (ParseException e) {
			throw new RMSException(e);
		}
	}

	/**
	 * Return the value associated with the column: end_date
	 */
	public java.util.Date getEnddate () {
		return enddate;
	}

	/**
	 * Set the value related to the column: end_date
	 * @param enddate the end_date value
	 */
	public void setEnddate (java.util.Date enddate) {
		this.enddate = enddate;
	}



	/**
	 * Return the value associated with the column: status
	 */
	public char getStatus () {
		return status;
	}

	/**
	 * Set the value related to the column: status
	 * @param status the status value
	 */
	public void setStatus (char status) {
		this.status = status;
	}



	/**
	 * Return the value associated with the column: resourceRates
	 */
	public java.util.Set<com.jkt.rms.business.Resource> getResourceRates () {
		return resourceRates;
	}

	/**
	 * Set the value related to the column: resourceRates
	 * @param resourceRates the resourceRates value
	 */
	public void setResourceRates (java.util.Set<com.jkt.rms.business.Resource> resourceRates) {
		this.resourceRates = resourceRates;
	}

	public void addToresourceRates (com.jkt.rms.business.Resource resource) {
		if (null == getResourceRates()) setResourceRates(new java.util.TreeSet<com.jkt.rms.business.Resource>());
		getResourceRates().add(resource);
	}





	public boolean equals (Object obj) {
		if (null == obj) return false;
		if (!(obj instanceof com.jkt.rms.business.Rate)) return false;
		else {
			com.jkt.rms.business.Rate rate = (com.jkt.rms.business.Rate) obj;
			return (this.getId() == rate.getId());
		}
	}

	public int hashCode () {
		if (Integer.MIN_VALUE == this.hashCode) {
			return (int) this.getId();
		}
		return this.hashCode;
	}

	public int compareTo (Object obj) {
		if (obj.hashCode() > hashCode()) return 1;
		else if (obj.hashCode() < hashCode()) return -1;
		else return 0;
	}

	public String toString () {
		return super.toString();
	}


}